<template>
    <view class="app">
        <view class="app-container padding-top">
            <view class="card" @tap="navigateToFileUpload(item)" v-for="(item, index) in list" :key="index">
                <view class="text-default text-default">{{item.name}}</view>
                <view class="text-gray margin-top-sm text-sm">{{item.describe}}</view>
                <view class="text-sl text-gray text-bold text-right block">￥{{item.one_side_unit_price}}</view>
            </view>
			<view class='noCommodity' v-if="!list.length">
			   <view class='pictrue'><image src='/static/img/noShopper.png'></image></view>
			</view>
        </view>
    </view>
</template>

<script>
    import {mapMutations} from 'vuex'
    import {getCloudPrintType} from "../api/print";

    export default {
        data() {
            return {
                list: [],
                type: ''
            };
        },
        onLoad(options) {
            this.type = options.type;
            this.initialize()
        },
        methods: {
            initialize() {
                const type = this.type;
                getCloudPrintType({
                    type: type
                }).then(res => {
                    this.list = res.result.showing
                });
            },
            /**
             * 点击文件类型
             * 跳转至上传文件页面
             * @param {Object} item 文件类型
             */
            navigateToFileUpload(item) {
                //第二步：获取支付参数
                getApp().globalData.uploadFileInfo['spec'] = item;
				uni.showActionSheet({
					itemList: ['微信导入'], // ['微信导入', '本地导入']
					success: res => {
						res.tapIndex === 0 && this.navigateToWechat();
						res.tapIndex === 1 && this.navigateToLocal()
					}
				});
            },
            /**
             * 微信文件上传
             */
            navigateToWechat() {
                // #ifndef MP
                uni.showToast({
                    title: '微信文件需在小程序平台上使用',
                    icon: 'none'
                });
                return;
                // #endif

                // #ifdef MP
                uni.navigateTo({
                    url: '/print-pages/wechat-file-upload'
                });
                // #endif
            },
            /**
             * 本地文件上传
             */
            navigateToLocal() {
                uni.navigateTo({
                    url: '/print-pages/local-file-upload'
                });
            }
        }
    };
</script>

<style lang="scss">
    .app {
        // background: url(~@/static/img/print/print-bg.png);
        background-repeat: no-repeat;
        background-size: cover;
        background-position: bottom;
    }
</style>
